home *** CD-ROM | disk | FTP | other *** search
- // By Judy D. Halchin, Educational Computing Services, Allegheny College.
- // You may freely copy, distribute and reuse this code.
- // Allegheny College and the author disclaim any warranty of any kind,
- // expressed or implied, as to its fitness for any particular use.
- // This work was partially supported by a Teacher Preparation grant from the
- // National Science Foundation.
-
- defineps drawBorders(float width, height, linePosition, borderWidth,
- backgroundGray, lineGray; boolean vertical, endBars)
-
- % width and height are unscaled here to get linewidths right
-
- gsave
-
- % background
- backgroundGray setgray
- 1 setalpha
- 0 0 width height rectfill
-
- % draw border if it should have one
- borderWidth 0 ge
- {
- % offsets to avoid part of the border being clipped off
- borderWidth 0 eq
- {/border 1 def}
- {/border borderWidth def}
- ifelse
-
- /offset border 2 div def
- /rightedge width offset sub def
- /topedge height offset sub def
- /bottomedge offset def
- /leftedge offset def
-
- % draw horizontal borders
- 0 bottomedge moveto
- width 0 rlineto
- 0 topedge moveto
- width 0 rlineto
-
- % draw vertical borders
- leftedge 0 moveto
- 0 height rlineto
- rightedge 0 moveto
- 0 height rlineto
-
- borderWidth setlinewidth
- 0 setgray
- stroke
- } if
-
- % draw end bars, if it should have them
- endBars
- {
- vertical
- {
- width linePosition sub 7 sub 1 moveto
- 15 0 rlineto
- -15 height 1 sub rmoveto
- 15 0 rlineto
- }
- {
- 0 linePosition 8 sub moveto
- 0 15 rlineto
- width 1 sub -15 rmoveto
- 0 15 rlineto
- } ifelse
-
- 0 setlinewidth
- lineGray setgray
- stroke
- } if
-
- grestore
-
- endps
-
-
-
- defineps drawLine(float originX, originY, width, height, scaleFactor;
- boolean vertical; float lineGray)
-
- % originX, originY, width, height are all scaled
-
- gsave
-
- % scale and translate to match number line, rotate if vertical
- vertical
- {
- 90 rotate
- scaleFactor 1 scale
- 0 height neg translate
- }
- {
- scaleFactor 1 scale
- }
- ifelse
-
- originX neg originY neg translate
-
- % draw the line itself
- originX 0 moveto
- width 0 rlineto
- lineGray setgray
- 0 setlinewidth
- stroke
-
- grestore
-
- endps
-
-
- defineps drawTicks(float originX, originY, height, scaleFactor;
- boolean vertical; float lineGray, firstTick, tickSpacing,
- firstLabel, labelSpacing; int numberOfTicks)
-
- gsave
-
- % scale and translate to match number line, rotate if vertical
- vertical
- {
- 90 rotate
- scaleFactor 1 scale
- 0 height neg translate
- }
- {
- scaleFactor 1 scale
- }
- ifelse
-
- originX neg originY neg translate
-
- % draw the ticks to the left of the first label
- firstLabel labelSpacing sub
- firstTick gt
- { /firstlabel firstLabel labelSpacing sub def }
- { /firstlabel firstLabel def }
- ifelse
-
- /margin tickSpacing 3 div def
- /tickCount 0 def
- firstTick -4 moveto
- {
- currentpoint pop
- margin add
- firstlabel gt {exit} if
-
- 0 7 rlineto
- /tickCount tickCount 1 add def
- tickSpacing -7 rmoveto
- } loop
-
- % draw rest of the ticks, with each fifth one larger
- /counter 5 def
- {
- counter 5 eq
- {
- 0 -4 rmoveto
- 0 15 rlineto
- tickSpacing -11 rmoveto
- /counter 0 def
- }
- {
- 0 7 rlineto
- tickSpacing -7 rmoveto
- } ifelse
-
- /counter counter 1 add def
- /tickCount tickCount 1 add def
- tickCount numberOfTicks eq
- { exit } if
- } loop
-
- lineGray setgray
- 0 setlinewidth
- 1 setalpha
- stroke
-
- grestore
-
- endps
-
-
- defineps drawHorzLabels(float originX, originY, scaleFactor, unscaleFactor;
- int labelPosition; float labelGray, firstLabel,
- labelSpacing; boolean scientific; int numberOfLabels;
- char *label1, *label2, *label3, *label4, *label5, *label6,
- *label7, *label8, *label9, *label10, *label11, *exponent1,
- *exponent2, *exponent3, *exponent4, *exponent5,
- *exponent6, *exponent7, *exponent8, *exponent9,
- *exponent10, *exponent11)
-
- gsave
-
- %scale and translate to match the number line
- scaleFactor 1 scale
- originX neg originY neg translate
-
- % set up the font
- /Helvetica findfont
- 10 scalefont
- setfont
- labelGray setgray
-
- % set the height for the labels
- labelPosition 1 eq
- { /labelHeight -18 def }
- { /labelHeight 10 def }
- ifelse
-
- % draw the labels
-
- /notZero (label1) (0) ne def
- firstLabel labelHeight moveto
- unscaleFactor 1 scale
- notZero
- {
- (label1) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- 2 div neg 0 rmoveto
- }
- {-3 0 rmoveto} ifelse
- (label1) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent1) show
- } if
- scaleFactor 1 scale
-
- /notZero (label2) (0) ne def
- firstLabel labelSpacing add labelHeight moveto
- unscaleFactor 1 scale
- notZero
- {
- (label2) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- 2 div neg 0 rmoveto
- }
- {-3 0 rmoveto} ifelse
-
- (label2) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent2) show
- } if
- scaleFactor 1 scale
-
- /notZero (label3) (0) ne def
- firstLabel labelSpacing add labelSpacing add labelHeight moveto
- unscaleFactor 1 scale
- notZero
- {
- (label3) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- 2 div neg 0 rmoveto
- }
- {-3 0 rmoveto} ifelse
- (label3) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent3) show
- } if
- scaleFactor 1 scale
-
- /notZero (label4) (0) ne def
- numberOfLabels 4 ge
- {
- firstLabel labelSpacing 3 mul add labelHeight moveto
- unscaleFactor 1 scale
- notZero
- {
- (label4) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- 2 div neg 0 rmoveto
- }
- {-3 0 rmoveto} ifelse
- (label4) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent4) show
- } if
- scaleFactor 1 scale
- } if
-
- /notZero (label5) (0) ne def
- numberOfLabels 5 ge
- {
- firstLabel labelSpacing 4 mul add labelHeight moveto
- unscaleFactor 1 scale
- notZero
- {
- (label5) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- 2 div neg 0 rmoveto
- }
- {-3 0 rmoveto} ifelse
- (label5) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent5) show
- } if
- scaleFactor 1 scale
- } if
-
- /notZero (label6) (0) ne def
- numberOfLabels 6 ge
- {
- firstLabel labelSpacing 5 mul add labelHeight moveto
- unscaleFactor 1 scale
- notZero
- {
- (label6) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- 2 div neg 0 rmoveto
- }
- {-3 0 rmoveto} ifelse
- (label6) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent6) show
- } if
- scaleFactor 1 scale
- } if
-
- /notZero (label7) (0) ne def
- numberOfLabels 7 ge
- {
- firstLabel labelSpacing 6 mul add labelHeight moveto
- unscaleFactor 1 scale
- notZero
- {
- (label7) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- 2 div neg 0 rmoveto
- }
- {-3 0 rmoveto} ifelse
- (label7) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent7) show
- } if
- scaleFactor 1 scale
- } if
-
- /notZero (label8) (0) ne def
- numberOfLabels 8 ge
- {
- firstLabel labelSpacing 7 mul add labelHeight moveto
- unscaleFactor 1 scale
- notZero
- {
- (label8) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- 2 div neg 0 rmoveto
- }
- {-3 0 rmoveto} ifelse
- (label8) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent8) show
- } if
- scaleFactor 1 scale
- } if
-
- /notZero (label9) (0) ne def
- numberOfLabels 9 ge
- {
- firstLabel labelSpacing 8 mul add labelHeight moveto
- unscaleFactor 1 scale
- notZero
- {
- (label9) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- 2 div neg 0 rmoveto
- }
- {-3 0 rmoveto} ifelse
- (label9) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent9) show
- } if
- scaleFactor 1 scale
- } if
-
- /notZero (label10) (0) ne def
- numberOfLabels 10 ge
- {
- firstLabel labelSpacing 9 mul add labelHeight moveto
- unscaleFactor 1 scale
- notZero
- {
- (label10) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- 2 div neg 0 rmoveto
- }
- {-3 0 rmoveto} ifelse
- (label10) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent10) show
- } if
- scaleFactor 1 scale
- } if
-
- /notZero (label11) (0) ne def
- numberOfLabels 11 ge
- {
- firstLabel labelSpacing 10 mul add labelHeight moveto
- unscaleFactor 1 scale
- notZero
- {
- (label11) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- 2 div neg 0 rmoveto
- }
- {-3 0 rmoveto} ifelse
- (label11) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent11) show
- } if
- scaleFactor 1 scale
- } if
-
- grestore
-
- endps
-
-
-
- defineps drawVertLabels(float originX, originY, height, scaleFactor,
- unscaleFactor; int labelPosition; float labelGray,
- firstLabel, labelSpacing; boolean scientific; int
- numberOfLabels;
- char *label1, *label2, *label3, *label4, *label5, *label6,
- *label7, *label8, *label9, *label10, *label11, *exponent1,
- *exponent2, *exponent3, *exponent4, *exponent5,
- *exponent6, *exponent7, *exponent8, *exponent9,
- *exponent10, *exponent11)
-
- gsave
-
- % scale and translate to match number line, but don't rotate
- 1 scaleFactor scale
- height originY add originX neg translate
-
- % set up the font
- /Helvetica findfont
- 10 scalefont
- setfont
- labelGray setgray
-
- % set the x coordinate for the labels
- labelPosition 1 eq
- { /labelPlace -10 def }
- { /labelPlace 10 def }
- ifelse
-
- % draw the labels
-
- /notZero (label1) (0) ne def
- labelPlace firstLabel moveto
- 1 unscaleFactor scale
- labelPosition 1 eq
- {
- (label1) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- neg
- }
- {0} ifelse
- -3 rmoveto
- (label1) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent1) show
- } if
- 1 scaleFactor scale
-
- /notZero (label2) (0) ne def
- labelPlace firstLabel labelSpacing add moveto
- 1 unscaleFactor scale
- labelPosition 1 eq
- {
- (label2) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- neg
- }
- {0} ifelse
- -3 rmoveto
- (label2) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent2) show
- } if
- 1 scaleFactor scale
-
- /notZero (label3) (0) ne def
- labelPlace firstLabel labelSpacing add labelSpacing add moveto
- 1 unscaleFactor scale
- labelPosition 1 eq
- {
- (label3) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- neg
- }
- {0} ifelse
- -3 rmoveto
- (label3) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent3) show
- } if
- 1 scaleFactor scale
-
- /notZero (label4) (0) ne def
- numberOfLabels 4 ge
- {
- labelPlace firstLabel labelSpacing 3 mul add moveto
- 1 unscaleFactor scale
- labelPosition 1 eq
- {
- (label4) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- neg
- }
- {0} ifelse
- -3 rmoveto
- (label4) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent4) show
- } if
- 1 scaleFactor scale
- } if
-
- /notZero (label5) (0) ne def
- numberOfLabels 5 ge
- {
- labelPlace firstLabel labelSpacing 4 mul add moveto
- 1 unscaleFactor scale
- labelPosition 1 eq
- {
- (label5) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- neg
- }
- {0} ifelse
- -3 rmoveto
- (label5) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent5) show
- } if
- 1 scaleFactor scale
- } if
-
- /notZero (label6) (0) ne def
- numberOfLabels 6 ge
- {
- labelPlace firstLabel labelSpacing 5 mul add moveto
- 1 unscaleFactor scale
- labelPosition 1 eq
- {
- (label6) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- neg
- }
- {0} ifelse
- -3 rmoveto
- (label6) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent6) show
- } if
- 1 scaleFactor scale
- } if
-
- /notZero (label7) (0) ne def
- numberOfLabels 7 ge
- {
- labelPlace firstLabel labelSpacing 6 mul add moveto
- 1 unscaleFactor scale
- labelPosition 1 eq
- {
- (label7) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- neg
- }
- {0} ifelse
- -3 rmoveto
- (label7) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent7) show
- } if
- 1 scaleFactor scale
- } if
-
- /notZero (label8) (0) ne def
- numberOfLabels 8 ge
- {
- labelPlace firstLabel labelSpacing 7 mul add moveto
- 1 unscaleFactor scale
- labelPosition 1 eq
- {
- (label8) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- neg
- }
- {0} ifelse
- -3 rmoveto
- (label8) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent8) show
- } if
- 1 scaleFactor scale
- } if
-
- /notZero (label9) (0) ne def
- numberOfLabels 9 ge
- {
- labelPlace firstLabel labelSpacing 8 mul add moveto
- 1 unscaleFactor scale
- labelPosition 1 eq
- {
- (label9) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- neg
- }
- {0} ifelse
- -3 rmoveto
- (label9) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent9) show
- } if
- 1 scaleFactor scale
- } if
-
- /notZero (label10) (0) ne def
- numberOfLabels 10 ge
- {
- labelPlace firstLabel labelSpacing 9 mul add moveto
- 1 unscaleFactor scale
- labelPosition 1 eq
- {
- (label10) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- neg
- }
- {0} ifelse
- -3 rmoveto
- (label10) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (exponent10) show
- } if
- 1 scaleFactor scale
- } if
-
- /notZero (label11) (0) ne def
- numberOfLabels 11 ge
- {
- labelPlace firstLabel labelSpacing 10 mul add moveto
- 1 unscaleFactor scale
- labelPosition 1 eq
- {
- (label11) stringwidth pop
- scientific notZero and {(x10 ) stringwidth pop add} if
- notZero not {( ) stringwidth pop add} if neg
- }
- {0} ifelse
- -3 rmoveto
- (label11) show
- scientific notZero and
- {
- 2 0 rmoveto
- (x) show
- 1 0 rmoveto
- (10) show
- 1 5 rmoveto
- (1) show
- } if
- 1 scaleFactor scale
- } if
-
- grestore
-
- endps
-
-
-
-